from .log import log
from .podcast.player import Player
from .podcast import diskmgr

player = Player()

def PlayFile(rel_filename, on_finish=None):
  global player
  filename = diskmgr.FullPath(rel_filename)
  player.stop()
  log(">>>>>>>>>>>>>> Playing", filename)
  player.play(filename, on_finish)

def Pause():
  global player
  assert not player.paused
  player.pause()

def Unpause():
  global player
  assert player.paused
  player.pause()

def Stop():
  player.stop()

def Playing():
  """Returns true if there is a current file playing, even if it is paused."""
  return player.playing

def Paused():
  return player.playing and player.paused

def SetSpeed(speed, accel):
  player.set_speed(speed, accel)

def QueryPosition():
  return player.position(), player.length()
